package xp2p.test.integration.files;

import java.io.File;
import java.net.URI;
import java.util.logging.Logger;
import net.jxta.peergroup.PeerGroup;
import net.jxta.platform.NetworkManager;
import xp2p.conf.BasicConfiguration;
import xp2p.svc.file.FileDownloader;

public class FileUser
{
	public static void main(String[] args)
	{
		try
		{
			BasicConfiguration conf = new BasicConfiguration();
			conf.TcpPort = 9771;
			conf.Rendezvous = false;
			conf.Relay = false;
			conf.StartURI = new URI("tcp://localhost:9701/");
			conf.HomeDir = new File(".cache1");
			conf.FileHomeDir = new File(".transfer1");
			NetworkManager nm = conf.Build();
			nm.startNetwork();
			Logger log = Logger.getLogger("Main");
			Thread.sleep(10000); // sleep for 10 secs
			PeerGroup group = nm.getNetPeerGroup();
			FileDownloader downloader = new FileDownloader();			
			downloader.setGroup(group);
			downloader.addDownload(new File("C:\\Users\\1\\Desktop\\123-result.txt"), "123");			
			Thread t = new Thread(downloader);
			t.start();
			Thread.sleep(2100000); // sleep for 10 secs
			t.interrupt();
			Thread.sleep(1000); // sleep for 10 secs
			nm.stopNetwork();
		} catch (Exception e)
		{
			// TODOL
			e.printStackTrace();
		}
	}
}
